<template>
  <div class="_wz_cent_main _wz_role">
    <Card :bordered="true" style="height: 100%;overflow: auto">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="addTableData">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer :title="formTitle" v-model="formOperation" width="720" :draggable="true" :mask-closable="false" :styles="formOperationStyles">
      <rolesAdd v-if="formOperation" :selectData="selectData" @closeFun="closeFun"></rolesAdd>
    </Drawer>

    <Drawer title="菜单功能授权" v-model="formOperation1" width="500" :draggable="true" :mask-closable="false">
      <rolesNav v-if="formOperation1" :selectData="selectData"></rolesNav>
    </Drawer>
  </div>
</template>
<script>
import menuAllot from './menuAllot.vue';
import wzTbale from "../../components/table/table";
import rolesAdd from './rolesAdd.vue';
import rolesNav from './rolesNav.vue';
export default {
  components: {
    menuAllot,//列表
    wzTbale,//列表
    rolesAdd,//添加
    rolesNav,//模块 菜单
  },
  data () {
    return {
      formOperation: false,//表单左侧移出
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      formOperation1: false,//表单左侧移出
      formTitle: "",//表单名称
      selectData: {},
      tableData: {
        url: this.apiUrl.systemRoleSystemRoleList,//请求地址
        method: 'post',//请求方式
        where: {},//搜索条件
        height: '100%',//表格高度 auto
        page: false,//分页是否使用
        columns: [//表头数据
          { type: 'index', width: 80, align: 'center', title: '序号', },
          { title: '角色名称', key: 'roleName', minWidth: 160, },
          { title: '角色标识', key: 'roleKey', minWidth: 140, },
          { title: '运输企业', key: 'deptName', minWidth: 260, },
          { title: '备注', key: 'comments', minWidth: 200, },
          { title: '创建时间', key: 'createTime', minWidth: 180, },
          {
            title: '操作', key: 'value', fixed: 'right', width: 180, render: (h, params) => {
              let operationButtons = [];
              //修改
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      var that = this
                      that.formTitle = "修改"
                      that.selectData = JSON.parse(JSON.stringify(params.row))
                      that.formOperation = true
                    }
                  }
                }, '修改')
              );

              //删除
              operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      var that = this
                      that.$Modal.confirm({
                        title: '删除提醒',
                        content: '确定要删除选中的记录？',
                        onOk: () => {
                          that.axios.post(that.apiUrl.systemRoleSystemRoleDelete, { roleId: params.row.roleId }).then(res => {
                            if (!!res) {
                              that.$Message.success('数据删除成功.')
                              that.$refs.wzTbale.tableLoadData()
                            }
                          }).catch(err => {
                            console.log("失败", err)
                          })
                        },
                        onCancel: () => {
                          //点击取消
                        }
                      })
                    }
                  }
                }, '删除')
              );

              //功能授权
              operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
              operationButtons.push(
                h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      var that = this
                      that.selectData = JSON.parse(JSON.stringify(params.row))
                      that.formOperation1 = true;
                    }
                  }
                }, '功能授权')
              );
              return h('div', operationButtons);
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
        },
      },

    }
  },
  beforeCreate () {//beforeCreate创建前状态

  },
  created () {//created创建完毕状态
  },
  beforeMount () {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted () {//mounted 挂载结束状态

  },
  methods: {//执行的方法
    addTableData () {//table添加
      this.formTitle = "添加"
      this.selectData = {};
      this.formOperation = true
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.formOperation = false;
      that.formOperation1 = false;
    },

  },
  watch: {//监听

  },
  beforeUpdate () {//beforeUpdate 更新前状态

  },
  updated () {//updated 更新完成状态

  },
  beforeDestroy () {//beforeDestroy 销毁前状态

  },
  destroyed () {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_role {
  .ivu-card-body {
    height: calc(100% - 51px);
  }
}
</style>
